class PubSub  {
    constructor () {
        this.subscribe = {}
    };
    add (key,fn) {
    
        if(!this.subscribe[key]){
            this.subscribe[key] = []
        }
        this.subscribe[key].push(fn);
    };
    remove (key) {
        delete this.subscribe[key]
    };
    publish () {
        let arg = arguments,key = [].shift.call(arg);
        if(this.subscribe[key].length <=0 || !this.subscribe[key]){
            return false
        }
        this.subscribe[key].map(item=>{
            item.apply(this,arg)
        })
        
    }
}

let pubSub = new PubSub();

pubSub.add ('name',(name)=>{
    console.log('your name is '+name)
})
pubSub.add ('color',(color)=>{
    console.log('this flower color is'+ color)
})

pubSub.publish('name','Eric');
pubSub.publish('color','red')